/**
 * 
 */
package org.cuatrovientos.struts.tulebox.example;

import java.util.Random;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author Dani
 * Class that generates an elvish/orcish name
 */
public class Names extends ActionSupport {
private String name="";
private int length;
private String race="";
private String[] orcs = {"kar", "ur", "og", "ag", "un"};
private String[] elves = {"sil", "dre", "dan", "in", "ir", "el"};
public String getName() {
	return name;
}
public void setName(String name) {
	this.name = name;
}
public int getLength() {
	return length;
}
public void setLength(int length) {
	this.length = length;
}
public String getRace() {
	return race;
}
public void setRace(String race) {
	this.race = race;
}

/**
 * This return an orcish/elvish name, generated with the elements of the arrays above
 */
@Override
public String execute(){
	Random r = new Random();
	
	if (race.equals("Orcish")){
		for(int i=0;i<length;i++){
			name += orcs[r.nextInt(orcs.length)];
		}
	}else{
		for(int i=0;i<length;i++){
			name += elves[r.nextInt(elves.length)];
		}
	}

	return SUCCESS;
}

}
